#include "BallThrow.h"

BallThrow::BallThrow(IWorld* wld)
{
	world = wld;
}

BallThrow::~BallThrow(void)
{
}

void BallThrow::Update(DWORD elapsedTime)
{
	if( EngineStuff::EInputManager->isMouseButtonPressing(DIMOUSE_RIGHTBUTTON) )
	{		
		XMVECTOR vec = world->GetCamera()->GetPosition();
		XMVECTOR targ = world->GetCamera()->GetTarget();	

		NxVec3 pos = NxVec3(XMVectorGetX(vec),XMVectorGetY(vec),XMVectorGetZ(vec) );
		NxVec3 tar = NxVec3(XMVectorGetX(targ),XMVectorGetY(targ),XMVectorGetZ(targ) );
		NxVec3 vel = tar - pos;
		vel = (vel/vel.normalize()) * 1;

		PhysxActor* dpo = new PhysxActor();
		NxBodyDesc bodyDesc;		
		bodyDesc.linearVelocity = vel;

		NxSphereShapeDesc sphereDesc;
		sphereDesc.radius = 1;

		dpo->actorDescription.shapes.pushBack(&sphereDesc);
		dpo->actorDescription.body			= &bodyDesc;
		dpo->actorDescription.density		= 10.0f;		
		dpo->actorDescription.globalPose.t  = pos;
		
		//IMesh* mesh = EngineStuff::EAssetManagment->LoadModel("C:/Users/tpastor/Documents/3dsMax/export/cam.xml","Box001");		
		IMesh* mesh = EngineStuff::EAssetManagment->LoadAssimpSingleModel("C:/Users/tpastor/Desktop/Release/Code/PloobsEngine/Etapa1/Content/Model/ball.X");

		IShader* shader = new SimpleShader();
		shader->Init("effect.fx","VS","vs_4_0","PS","ps_4_0",*InputLayouts::PositionTextureNormalLayout);
		
		IObject* object = new IObject(mesh,shader,dpo);
		world->AddObject(object);
	}
}
